package com.framework.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *工具
 * @author T
 *
 */
public class Tooles
{
	/**
	 * Email地址验证规则
	 */
    final static String checkPattern = "^([a-z0-9A-Z]+[_|\\-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
    final static Pattern pattern = Pattern.compile(checkPattern);
	
	
	
	
	
	
	public static void main(String[] args)
	{
		
//		String temp="1989-11-10 17:39:33";
//		System.out.println(stringToDate(temp));
//		System.out.println((new Date()));
//		System.out.println(dateToString(new Date()));
//		System.out.println(timeDifference(new Date(),stringToDate(temp)));
	}
	
	
	/**
	 * 验证字符串不等于null并且不等于 ""
	 * @param temp
	 * @return
	 */
	public static boolean isNotNull(String temp)
	{
		if(temp!=null&&!"".equals(temp.trim()))
		{
			return true;
		}else
		{
			return false;
		}
	}
	
	
	/**
	 * 获取当前时间
	 * @return
	 */
	public static Date getCurrentDate()
	{
		Date date=new Date();
		return date;
	}
	
	/**
	 * 日期转字符串
	 * @param date
	 * @return
	 */
	public static String dateToString(Date date)
	{
		SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return simpleDateFormat.format(date);
	}
	
	/**
	 * 字符串转日期
	 * @param date
	 * @return
	 */
	public static Date stringToDate(String date)
	{
		SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try
		{
			return simpleDateFormat.parse(date);
		}
		catch (ParseException e)
		{
			e.printStackTrace();
			return null;
		}
	}
	
 
    /**
     * 计算两个时间之间相差的天数（传入需要比较的两个时间，不区分顺序）
     * @param dateA
     * @param dateB
     * @return
     */
    public static Integer timeDifference(Date dateA ,Date dateB)
    {
    	Long a=dateA.getTime();
    	Long b=dateB.getTime();
    	Long days =Math.abs(a-b) / (24 * 60 * 60 * 1000);   
        return days.intValue();
    }
	
    
    /**
     * 获取当前时间的字符串
     * @return
     */
    public static String getCurrentDateString()
    {
    	SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return simpleDateFormat.format(new Date());
    }
    
    
    

    /**
     * 
     * @param email
     * @return
     */
   public static Boolean validateEmail(String email)
   {
		Matcher matcher = pattern.matcher(email);
		return matcher.matches();
   }
}
